﻿using course.message.Common;
using course.message.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace course.message.ViewModel
{
    public class LoginViewModel : NotifyBase
    {
        public CommandBase CloseWindowCommand { get; set; }
        public LoginModel LoginModel { get; set; } = new LoginModel();
        public CommandBase LoginCommand { get; set; }
        public string _errorMessage;
        public string ErrorMessage
        {
            get { return _errorMessage; }
            set { _errorMessage = value; this.DoNotify(); }
        }
        public LoginViewModel() {
            this.CloseWindowCommand = new CommandBase();
            this.CloseWindowCommand.DoExecute = new Action<object>((o)=> {
                (o as Window).Close();
            });
            this.CloseWindowCommand.DoCanExecute = new Func<object, bool>((o)=> 
            {
                return true;
            });

            this.LoginCommand = new CommandBase();
            this.LoginCommand.DoExecute = new Action<object>(DoLogin);
            this.LoginCommand.DoCanExecute = new Func<object, bool>((o)=> 
            {
                return true;
            });
        }

        private void DoLogin(object obj)
        {
            this.ErrorMessage = "";
            if (string.IsNullOrEmpty(LoginModel.UserName))
            {
                this.ErrorMessage = "请输入用户名";
                return;
            }
            if (string.IsNullOrEmpty(LoginModel.Passowrd))
            {
                this.ErrorMessage = "请输入密码";
            }
        }
    }
}
